package cn.edu.nju.software.action.user;

import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import cn.edu.nju.software.bean.show.UserShow;
import cn.edu.nju.software.service.intf.UserService;
import cn.edu.nju.software.util.Constants;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class ModifyUserInfoAction extends ActionSupport implements SessionAware {

	private String name;
	private String email;
	private String phone;
	private UserService userService;
	private Map<String, Object> session;

	public void setName(String name) {
		this.name = name;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	@Override
	public String execute() throws Exception {
		if (name == null || email == null || phone == null) {
			return INPUT;
		}
		UserShow userOld = (UserShow) session.get(Constants.SESSION_USER);
		userOld.setName(name);
		userOld.setEmail(email);
		userOld.setPhone(phone);
		userService.updateUser(userOld.getUser());
		return SUCCESS;
	}
	
}
